package ca.liu.scaffoldingmvctest.dao;

import ca.liu.scaffoldingmvctest.domain.StLog;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage StLog entities.
 * 
 */
@Repository("StLogDAO")
@Transactional
public class StLogDAOImpl extends AbstractJpaDao<StLog> implements StLogDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { StLog.class }));

	/**
	 * EntityManager injected by Spring for persistence unit org_postgresql_Driver
	 *
	 */
	@PersistenceContext(unitName = "org_postgresql_Driver")
	private EntityManager entityManager;

	/**
	 * Instantiates a new StLogDAOImpl
	 *
	 */
	public StLogDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findStLogByValue
	 *
	 */
	@Transactional
	public Set<StLog> findStLogByValue(String value) throws DataAccessException {

		return findStLogByValue(value, -1, -1);
	}

	/**
	 * JPQL Query - findStLogByValue
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<StLog> findStLogByValue(String value, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findStLogByValue", startResult, maxRows, value);
		return new LinkedHashSet<StLog>(query.getResultList());
	}

	/**
	 * JPQL Query - findStLogById
	 *
	 */
	@Transactional
	public StLog findStLogById(Integer id) throws DataAccessException {

		return findStLogById(id, -1, -1);
	}

	/**
	 * JPQL Query - findStLogById
	 *
	 */

	@Transactional
	public StLog findStLogById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findStLogById", startResult, maxRows, id);
			return (ca.liu.scaffoldingmvctest.domain.StLog) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findStLogByValueContaining
	 *
	 */
	@Transactional
	public Set<StLog> findStLogByValueContaining(String value) throws DataAccessException {

		return findStLogByValueContaining(value, -1, -1);
	}

	/**
	 * JPQL Query - findStLogByValueContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<StLog> findStLogByValueContaining(String value, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findStLogByValueContaining", startResult, maxRows, value);
		return new LinkedHashSet<StLog>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllStLogs
	 *
	 */
	@Transactional
	public Set<StLog> findAllStLogs() throws DataAccessException {

		return findAllStLogs(-1, -1);
	}

	/**
	 * JPQL Query - findAllStLogs
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<StLog> findAllStLogs(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllStLogs", startResult, maxRows);
		return new LinkedHashSet<StLog>(query.getResultList());
	}

	/**
	 * JPQL Query - findStLogByPrimaryKey
	 *
	 */
	@Transactional
	public StLog findStLogByPrimaryKey(Integer id) throws DataAccessException {

		return findStLogByPrimaryKey(id, -1, -1);
	}

	/**
	 * JPQL Query - findStLogByPrimaryKey
	 *
	 */

	@Transactional
	public StLog findStLogByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findStLogByPrimaryKey", startResult, maxRows, id);
			return (ca.liu.scaffoldingmvctest.domain.StLog) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(StLog entity) {
		return true;
	}
}
